//
//  ECPrivacyAgreementVc.m
//  Edu_iOS2018
//
//  Created by apple on 2018/3/6.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#import "ECPrivacyAgreementVc.h"
#import<WebKit/WebKit.h>
#import "UIImage+Color.h"

@interface ECPrivacyAgreementVc ()<WKUIDelegate,WKNavigationDelegate>{
    WKWebView *webView;
}

@end

@implementation ECPrivacyAgreementVc

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar lt_reset];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"navigation_Return"] style:UIBarButtonItemStylePlain target:self action:@selector(action_dismiss)];
    /*  导航栏字体  */
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#333333"]}];
    //
    /*  导航栏线  */
    [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#BFBFBF"] size:CGSizeMake(self.view.frame.size.width, 0.5)]];
    
    [self loadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"服务协议";
    
    webView = [[WKWebView alloc]init];
    [self.view addSubview:webView];
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(self.view);
        make.bottom.equalTo(self.view);
    }];
    webView.UIDelegate = self;
    webView.navigationDelegate = self;
}

-(void)loadData{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HWHttpTool requestWithMethod:@"GET"
                              url:URL_GET_Mobileschools
                           params:nil
                          headers:nil
                          success:^(id json) {
                              if ([json[@"code"] intValue] == 200) {
                                  [MBProgressHUD hideHUDForView:self.view animated:YES];
                                  [webView loadHTMLString:json[@"data"][@"user_terms_body"] baseURL:nil];
                              }
                        } failure:^(NSError *error) {
                            [MBProgressHUD hideHUDForView:self.view animated:YES];
                            [MBProgressHUD showTipMessageInWindow:@"数据请求失败,请重试"];
                          }];
}

// WKNavigationDelegate 页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    //修改字体大小 300%
    [webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '200%'"completionHandler:nil];
    //修改字体颜色  #9098b8
    [ webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= '#222222'"completionHandler:nil];
}

-(void)action_dismiss{
    [self.navigationController.navigationBar lt_setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0]];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
